package com.mark.spring.annotation.life.cycle.beanpostprocessor;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @Description: Bean 后置处理器
 * @Author: Mark
 * @CreateDate: 2019/9/17 21:40
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 *
 * @see BeanPostProcessor
 *
 * IOC容器在初始化单例Bean的时候
 * 1.{@link AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsBeforeInitialization(java.lang.Object, java.lang.String)} 遍历执行BeanPostProcess的postProcessBeforeInitialization()方法
 * 2.{@link AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterInitialization(java.lang.Object, java.lang.String)} 遍历执行BeanPostProcess的postProcessAfterInitialization()方法
 *
 * Spring底层对BeanPostProcessor的使用
 * @see ApplicationContextAwareProcessor
 * @see AutowiredAnnotationBeanPostProcessor
 * @see InitDestroyAnnotationBeanPostProcessor
 */
@ComponentScan(
        basePackages = {
                "com.mark.spring.annotation.life.cycle.beanpostprocessor",
                "com.mark.spring.annotation.life.cycle.postconstruct"
        }
)
public class BeanPostProcessorBootstrap {

    public static void main(String[] args) {
        //加载配置，获取bean
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(BeanPostProcessorBootstrap.class);

        //关闭上下文
        applicationContext.close();
    }
}
